package com.baosight.risk.web.system;

import com.baosight.risk.api.xtzy.IXtzyUserService;
import com.baosight.risk.base.redis.BaseRedis;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author duanyongqiang
 */
@Controller
@RequestMapping("test")
@Slf4j
public class TestRedis {

    @Autowired
    private IXtzyUserService userService;

    @Autowired
    private BaseRedis baseRedis;

    @RequestMapping("list")
    @ResponseBody
    public Object test() {
        String key = "key";
        log.info(userService.selectAll().toString());
        if (!baseRedis.isKey(key)) {
            baseRedis.setValue(key, userService.selectAll());
        }
        return baseRedis.getValue(key);
    }

    @RequestMapping("delete")
    @ResponseBody
    public String delete() {
        String key = "luock_key";
        //增加redis锁
        if (baseRedis.louck(key)) {

            //业务逻辑
            baseRedis.delete("key");

//            //释放锁
            baseRedis.unLouck(key);
        } else {
            return "稍等、、";
        }
        return "delete";
    }

}
